#ifndef MYIMAGEVIEW_H
#define MYIMAGEVIEW_H

#include <QGraphicsView>
#include <memory>
#include <QImage>
#include <opencv2/opencv.hpp>

class MyImageView : public QGraphicsView
{
    Q_OBJECT
public:
    explicit MyImageView(QWidget *parent = nullptr);
    ~MyImageView() override = default;
    void zoom(double scaleFactor);

protected:
    /*
     * 滚轮缩放
     * 左右键平移
     * 中键保存图像
     */
//    void mousePressEvent(QMouseEvent *event) override;
//    void mouseReleaseEvent(QMouseEvent *event) override;
//    void mouseMoveEvent(QMouseEvent *event) override;
//    void mouseDoubleClickEvent(QMouseEvent *event) override;
    void wheelEvent(QWheelEvent *e) override;

public slots:
    bool showImage(cv::Mat image);
    bool showImage(QImage image);
Q_SIGNALS:
    void pixelInfo(std::vector<int> &pix_site, std::vector<uint8_t> &pix_info);

private:
    QGraphicsScene *m_scene;
    cv::Mat m_imgRender; // 渲染的图片，保留一次引用
    QImage m_qimgRender; // 渲染的图片，保留一次引用
    QGraphicsPixmapItem *m_pixmapItem = nullptr;

    volatile bool m_dragFlag = false; // 鼠标拖拽状态
    volatile bool m_moveFlag = false; // 鼠标拖拽状态下进行了移动
    QPoint m_dragPos;                 // 鼠标拖拽位置，在窗口中的坐标
    QPointF m_centerPosInScene;       // 鼠标拖拽位置，在场景中的坐标
    std::vector<int> m_pix_site = std::vector<int>(2, 0); // 当前鼠标位置的像素在图片的位置
    std::vector<uint8_t> m_pix_info;
    int count = 0;// 当前鼠标位置的像素在图片的像素信息
};

#endif // MYIMAGEVIEW_H
